<template>
  <div>
    <el-dialog
      title="编辑通知"
      :visible.sync="noticeVisible"
      width="40%"
      :show-close="false"
      :close-on-click-modal="false">
      <el-form ref="noticeForm" :model="noticeForm" :rules="noticeForm_rules" label-width="110px">
        <el-form-item label="内容" prop="n_content">
          <el-input v-model="noticeForm.n_content" size="small" style="width: 80%"></el-input>
        </el-form-item>
        <el-form-item label="开始时间" prop="n_start_time">
          <el-date-picker size="mini"
                          v-model="noticeForm.n_start_time"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          type="datetime"
                          placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="n_end_time">
          <el-date-picker size="mini"
                          v-model="noticeForm.n_end_time"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          type="datetime"
                          placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="closeDialog">取 消</el-button>
      <el-button size="mini" type="primary" @click="addInfo">确 定</el-button>
    </span>
    </el-dialog>
  </div>
</template>
<script>
  import {addNotice,deleteNotices,updateNoticeById,findNoticeByPage,queryNoticeNowTime} from '@/api/system'

  export default {
      props:["isShowEdit","row"],
      created(){
          this.noticeForm = JSON.parse(JSON.stringify(this.row));
      },
      data(){
          return {
            noticeVisible:this.isShowEdit,

            noticeForm:{
              n_id:"",
              n_title:"",
              n_content:"",
              n_start_time:"",
              n_end_time:""
            },

            noticeForm_rules:{
              n_content:[{ required: true, message: '不能为空', trigger: 'change' }],
              n_start_time:[{ required: true, message: '不能为空', trigger: 'change' }],
              n_end_time:[{ required: true, message: '不能为空', trigger: 'change' }],
            }
          }
      },
      methods:{
        closeDialog(){
          this.noticeVisible = false;
          this.$emit("closeDialog","edit");
        },

        addInfo(){
          this.$refs["noticeForm"].validate((valid) => {
            if(valid){
              updateNoticeById(this.noticeForm).then(res=>{
                  if(res.code == 200){
                    this.$message({
                      message: '修改成功',
                      type: 'success'
                    });
                    this.closeDialog();
                  }
              })
            }
          });
        }
      }
  }
</script>
